import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/model/exam_question.dart';

import 'option_type.dart';

class OptionWidget extends StatelessWidget {
  final OptionType type;
  final AnswerOption option;

  const OptionWidget({
    Key key,
    @required this.type,
    @required this.option,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 10, vertical: 8),
      margin: EdgeInsets.only(top: 20),
      decoration: BoxDecoration(
        color: bgColor(),
        border: Border.all(color: borderColor()),
        borderRadius: BorderRadius.circular(8),
      ),
      child: Row(
        children: [
          dot(),
          Expanded(child: label()),
          if (type == OptionType.successAndChecked)
            Icon(
              Icons.check,
              color: labelColor(),
            ),
          if (type == OptionType.error)
            Icon(
              Icons.close,
              color: labelColor(),
            ),
        ],
      ),
    );
  }

  Widget dot() {
    return Container(
      padding: EdgeInsets.all(6),
      alignment: Alignment.center,
      decoration: BoxDecoration(
        color: dotBgColor(),
        border: Border.all(color: dotBorderColor()),
        shape: BoxShape.circle,
      ),
      child: Text(
        option.key,
        style: TextStyle(
          color: type == OptionType.noraml ? dotBorderColor() : Colors.white,
        ),
      ),
    );
  }

  Widget label() {
    return Padding(
      padding: EdgeInsets.only(left: 10),
      child: Text(
        option.option,
        softWrap: true,
        style: TextStyle(
          color: labelColor(),
        ),
      ),
    );
  }

  Color labelColor() {
    switch (type) {
      case OptionType.noraml:
        return Color.fromRGBO(68, 68, 68, 1);
      case OptionType.primary:
        return Color.fromRGBO(12, 120, 242, 1);
      case OptionType.success:
      case OptionType.successAndChecked:
        return Color.fromRGBO(50, 199, 124, 1);
      case OptionType.error:
        return Color.fromRGBO(255, 115, 97, 1);
      default:
        return Color.fromRGBO(68, 68, 68, 1);
    }
  }

  Color dotBorderColor() {
    switch (type) {
      case OptionType.noraml:
        return Color.fromRGBO(153, 153, 153, 1);
      case OptionType.primary:
        return Color.fromRGBO(38, 139, 255, 1);
      case OptionType.success:
      case OptionType.successAndChecked:
        return Color.fromRGBO(82, 204, 141, 1);
      case OptionType.error:
        return Color.fromRGBO(255, 154, 140, 1);
      default:
        return Color.fromRGBO(153, 153, 153, 1);
    }
  }

  Color dotBgColor() {
    switch (type) {
      case OptionType.noraml:
        return Color.fromRGBO(250, 250, 250, 1);
      case OptionType.primary:
        return Color.fromRGBO(77, 160, 255, 1);
      case OptionType.success:
      case OptionType.successAndChecked:
        return Color.fromRGBO(102, 211, 159, 1);
      case OptionType.error:
        return Color.fromRGBO(255, 115, 97, 1);
      default:
        return Color.fromRGBO(250, 250, 250, 1);
    }
  }

  Color bgColor() {
    switch (type) {
      case OptionType.noraml:
        return Color.fromRGBO(250, 250, 250, 1);
      case OptionType.primary:
        return Color.fromRGBO(237, 243, 250, 1);
      case OptionType.success:
      case OptionType.successAndChecked:
        return Color.fromRGBO(240, 250, 245, 1);
      case OptionType.error:
        return Color.fromRGBO(255, 244, 242, 1);
      default:
        return Color.fromRGBO(250, 250, 250, 1);
    }
  }

  Color borderColor() {
    switch (type) {
      case OptionType.noraml:
        return Color.fromRGBO(224, 224, 224, 1);
      case OptionType.primary:
        return Color.fromRGBO(77, 160, 255, 1);
      case OptionType.success:
      case OptionType.successAndChecked:
        return Color.fromRGBO(82, 204, 141, 1);
      case OptionType.error:
        return Color.fromRGBO(255, 154, 140, 1);
      default:
        return Color.fromRGBO(224, 224, 224, 1);
    }
  }
}
